package simplyrugby.controller;


import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import simplyrugby.common.Result;
import simplyrugby.entity.Menu;
import simplyrugby.service.MenuService;

import java.util.List;

@RestController
@RequestMapping("/api/menu")
@RequiredArgsConstructor
public class MenuController {
    private final MenuService menuService;


    @PostMapping
    public Result add(@RequestBody Menu menu) {
        boolean save = menuService.save(menu);
        return Result.success().data(save);
    }

    @DeleteMapping("/{id}")
    public Result removeById(@PathVariable String id) {
        boolean b = menuService.removeById(id);
        return Result.success().data(b);
    }

    @PutMapping
    public Result updateById(@RequestBody Menu menu) {
        boolean flag = menuService.updateById(menu);
        return flag ? Result.success() : Result.fail();
    }


    @GetMapping("/{id}")
    public Result details(@PathVariable String id) {
        Menu menu = menuService.getById(id);
        return Result.success().data(menu);
    }

    @GetMapping("/list")
    public Result list() {
        List<Menu> list = menuService.list();
        return Result.success().data(list);
    }

}


